This is the sixth in a series of lessons on the use of the QCard32.DLL.
Where to Find QCard32.DLL
This series of lessons uses the Qcard32.dll, a freeware library of playing card images. It is written by Stephen Murphy. Qcard32.DLL website: [http://www.telusplanet.net/public/stevem/] You can also obtain a copy of the DLL in issue #120 of the Liberty BASIC Newsletter.
What is in QCard32.DLL?
The DLL includes card face images for all suits and number values, from Ace to King, with hearts, spades, diamonds and clubs. There is a choice of six card backs. There are also jokers. It doesn't just provide images, though. It provides a way to manage the cards.
Keeping Track of Cards on the Table
This demo removes cards from the table after the user clicks on them. If he clicks in the same spot again, our program knows that the card has already been removed, so the program does not procede to the routine that retrieves the suit and value of the card. It just waits for the user to click somewhere else. If a card has been removed, it can no longer be accessed.
To accomplish this, we add a second dimension to card array to indicate whether it is on the table or if it has been removed.
'card(n,1)=index of card in deck 'card(n,2)=visible on table? 1=yes, 0=no
After filling the card array with suits and values, we set each card's second dimension to 1, to indicate that it is present on the table. We do this quite easily in a FOR...NEXT loop.
[fillCardArray]
'fill card array
'cards 1 to 52 are in the first deck
'cards 53 to 104 are in the second deck
'use cards Jack through King in each suit, first deck
card(1,1)=11 'jack of clubs
card(2,1)=12 'queen
card(3,1)=13 'king
card(4,1)=24 'jack of diamonds
card(5,1)=25 'queen
card(6,1)=26 'king
card(7,1)=37 'jack of hearts
card(8,1)=38 'queen
card(9,1)=39 'king
card(10,1)=50 'jack of spades
card(11,1)=51 'queen
card(12,1)=52 'king
'now use second deck, to fill second half of array
for i = 1 to 12
card(i+12,1)=card(i,1)+52
next
RETURN
[shuffleCards]
'first set all cards as visible, card(n,2)=1
for i = 1 to 24
card(i,2)=1
next
Checking to see if a card is still on the table.
In the routine to see which card is clicked, we also check to see if the card has already been removed. If the second dimension in the card array for that index is 0, the card has already been removed. If it is 1, it is still on the table. If it has been removed, we simply wait. If it hasn't, we go on to read the value and do other stuff.
'if card is not visible (has been removed), then wait
if card(clickCard,2)=0 then wait
gosub [readValue]
wait
Removing a card from the table.
If the card has not already been removed, we remove it and set the second dimension of the card array for that index to 0.
'remove card
call RemoveCard hBox, card(clickCard,1)
'set visible to 'off'
card(clickCard,2)=0
DEMO
See cards6.bas in the zipped archive of this issue for the demo program. The zip file also includes the wav sounds.
Next time...
In the next installment, we'll remove cards if they match. We now have our methods in place to see if a card is still on the table, and to retrieve its suit and value, so checking for a match will be easy! Feel free to work out the method yourself!